#define  _CRT_SECURE_NO_WARNINGS
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        ListNode guard, * prev = &guard;
        prev->next = head;
        while (prev->next && prev->next->next)
        {
            ListNode* cur1 = prev->next, * cur2 = cur1->next, * pNext = cur2->next;
            prev->next = cur2;
            cur2->next = cur1;
            cur1->next = pNext;
            prev = cur1;
        }
        return guard.next;
    }
};